/*package MapRelated;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import ChatPackage.ChatHandler;
import Database.Database;
import TomcatRelated.TomcatProtocolImp;
import TomcatRelated.UserProfile;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
import android.widget.ZoomControls;
import androidApplication.javaFiles.*;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class MapManager 
{
	//***************************************Class Variables*******************************************

	private MapView _mapView;
	private LocationManager _locManager;
	private LocationListener _locListener;
	private UsersOverlay _iconOverlay;
	private Drawable _icon;

	
	//handler.postDelayed(zoomChecker, zoomCheckingDelay); //starting the thread loop
		private Handler handler = new Handler();
	public static final int zoomCheckingDelay = 5000; // in ms

	private Runnable zoomChecker = new Runnable()
	{
	    public void run()
	    {
	        
	    	updateIconsOverlay();

	        handler.removeCallbacks(zoomChecker); // remove the old callback
	        handler.postDelayed(zoomChecker, zoomCheckingDelay); // register a new one
	    }
	};

	//***************************************Constructors*******************************************

	public MapManager(MapView mapView)
	{
		this._mapView = mapView;
		initLocationObjects();
		addZoomToMap();
		focusMapOnIsrael();
		addBasicOverlay();
		//addOSMOverlay();
		addMessagesIcon();
		addIconsOverlay();
	}


	//***************************************Public Methods*******************************************

	*//**
	 * add the message icon but without showing it
	 *//*
	private void addMessagesIcon() {
		// TODO Auto-generated method stub

	}

	//init the objects that used to get the GPS location
	private void initLocationObjects() 
	{
		Log.v("Update Position","Starting Location Objects");
		// Acquire a reference to the system Location Manager
		this._locManager = (LocationManager) this._mapView.getContext().getSystemService(Context.LOCATION_SERVICE);

		// Define a listener that responds to location updates
		this._locListener = new LocationListener() {

			*//**
			 * Called when a new location is found by the network location provider.
			 *//*
			public void onLocationChanged(Location location) 
			{
				Log.v("Update Position","Location changed");
				handleLocationChanged(location.getLatitude(), location.getLongitude());
			}

			*//** 
			 * This method is called when a provider is unable to fetch a location or if the
			 * provider has recently become available after a period of unavailability. 
			 *//*
			public void onStatusChanged(String provider, int status, Bundle extras) 
			{
				Log.v("Update Position","status changed");
			}

			public void onProviderEnabled(String provider) 
			{
				Runnable run = new Runnable() {
					public void run() {
						createOkDialog("GPS Signal is on").show();
					}
				};
				Thread trd = new Thread(run);
				trd.run();

			}

			public void onProviderDisabled(String provider) 
			{
				
				Log.v("Update Position","Provider Disabled");
				Runnable run = new Runnable() {
					public void run() {
						createOkDialog("No GPS Signal, check your settings.").show();
					}
				};
				Thread trd = new Thread(run);
				trd.run();
				
				
			}
		};
		startLocationUpdates();

	}


	public void startLocationUpdates()
	{
		// Register the listener with the Location Manager to receive location updates
		Log.v("Update Position","Starting Location Updates");
		this._locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 10, _locListener);
		//time is in milisec. 1000milisec = 1sec. here the time is 60,000 milisec = 1 min
		//the distance is in meters. here we will get updates if the device moved 10 meter
		//the supplied LocationListener will be called with the current Location or with status updates. 
	}


	public void stopLocationUpdates()
	{
		// Remove the listener you previously added
		Log.v("Update Position","Stopping Location Updates");
		this._locManager.removeUpdates(this._locListener);
	}


	public MapView getMapView()
	{
		return this._mapView;
	}


	public void setTraffic(boolean b) 
	{
		this._mapView.setTraffic(b);
	}


	public void setSatellite(boolean b) 
	{
		this._mapView.setSatellite(b);
	}


	public void setStreetView(boolean b) 
	{
		this._mapView.setStreetView(b);
	}


	public void setVisibility(boolean b) 
	{
		if (b)
		{
			this._mapView.setVisibility(View.VISIBLE);
		}
		else
		{
			this._mapView.setVisibility(View.INVISIBLE);
		}

	}	


	//***************************************Private Methods*******************************************

	private void handleLocationChanged(double latitude, double longitude) 
	{
		// TODO implement this method!
		Toast.makeText(this._mapView.getContext(), "location changed!",Toast.LENGTH_LONG).show();
		String coordinates[] = {String.valueOf(latitude),String.valueOf(longitude)}; //coordinates of Israel
		focusMapOnPoint(coordinates,16);
		String my_android_id = Database.getInstance(this._mapView.getContext()).get_device_id();
		//sending update to server
		TomcatProtocolImp.getInstance().updatePosition(my_android_id, latitude, longitude);
	}

	private void showMeOnMap(){
		//TomcatClient.getTomcatClient();
	}

	//center the map on Israel.
	private void focusMapOnIsrael() 
	{
		String coordinates[] = {"31.644029", "34.956665"}; //coordinates of Israel
		focusMapOnPoint(coordinates,8);
	}


	//center the map on the coordinates recieverd.
	//center the map on the coordinates recieverd. 
	//if zoom is between 1 to 21, other values will cause no change in zoom
	private void focusMapOnPoint(String[] coordinates, int zoom) 
	{
		MapController mapController = this._mapView.getController();

		GeoPoint gp = getGeoPointFromCoordinate(coordinates);

		mapController.animateTo(gp);
		if (zoom > 0 && zoom < 22){
			mapController.setZoom(zoom);
		}
		_mapView.postInvalidate();
	}


	//Setting the zoom button & setting the map initially invisible.
	private void addZoomToMap() 
	{
		this._mapView.setBuiltInZoomControls(true);
	}


	private void addIconsOverlay()
	{
		Context context = this._mapView.getContext();
		Resources resources = context.getResources();
		_icon = resources.getDrawable(R.drawable.overlay_item);
		_icon.setBounds(0, 0, _icon.getIntrinsicWidth(), _icon.getIntrinsicHeight());
		_iconOverlay = new UsersOverlay(_icon, this._mapView);
		updateIconsOverlay();
		
}
	
	private void updateIconsOverlay()
	{
		//_iconOverlay.removeAllItems(); //initializing the icons ArrayList
		//could be constant....
		Display display = ((WindowManager) this._mapView.getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		int width = display.getWidth();
		int height = display.getHeight();
		
		
		GeoPoint bottom_right = this._mapView.getProjection().fromPixels(width, height);
		GeoPoint upper_left = this._mapView.getProjection().fromPixels(0, 0);
		System.out.println("addIcons = ("+upper_left.getLatitudeE6()/1E6+","+upper_left.getLongitudeE6()/1E6+") , ("+
				bottom_right.getLatitudeE6()/1E6+","+bottom_right.getLongitudeE6()/1E6+")");
		
		//sends a request to server to get users in screen
		Vector<UserProfile> allUsers = TomcatProtocolImp.getInstance().getUsersPosition(
			upper_left.getLatitudeE6()/1E6,upper_left.getLongitudeE6()/1E6,
				bottom_right.getLatitudeE6()/1E6,bottom_right.getLongitudeE6()/1E6);
		
		if (allUsers != null && allUsers.size() != 0){
			Log.v("MapManager", "******** adding icons to map");
			
			
			for (Iterator iterator = allUsers.iterator(); iterator.hasNext();) {
				UserProfile user = (UserProfile) iterator.next();
				String coordinates[] = {String.valueOf(user.getX()),String.valueOf(user.getY())};
				GeoPoint point = MapManager.getGeoPointFromCoordinate(coordinates);
				_iconOverlay.addItem(_iconOverlay.new MyOverlayItem(point, "Israel", user.get_android_id(),0));
				//TODO - change the title of the item from Israel to address (in the future)
			}
			List<Overlay> listOfOverlays = this._mapView.getOverlays();
			listOfOverlays.add(_iconOverlay);

		}
		else{
			List<Overlay> listOfOverlays = this._mapView.getOverlays();
			listOfOverlays.remove(_iconOverlay);

			Log.v("MapManager", "********* no icons to add to map");
		}
		this._mapView.postInvalidate();
		
		

	}

	
	//adding the open-street-map overlay over our google map overlay 
	private void addOSMOverlay()
	{
		Context context = this._mapView.getContext();

		MapTileProviderBasic mProvider = new MapTileProviderBasic(context);
		//		mProvider.setTileSource(TileSourceFactory.MAPNIK);
		mProvider.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
		Overlay mTilesOverlay = new OSMOverlay(mProvider, context);
		this._mapView.getOverlays().add(0, mTilesOverlay);

		this._mapView.postInvalidate();
	}
	 

	private void addBasicOverlay()
	{
		Overlay overlay = new BasicMapOverlay();
		this._mapView.getOverlays().add(overlay);

		this._mapView.postInvalidate();
	}


	public static GeoPoint getGeoPointFromCoordinate(String[] coordinates)
	{
		double lat = Double.parseDouble(coordinates[0]);
		double lng = Double.parseDouble(coordinates[1]);

		return new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6));
	}

	
	 * changing the activity to send messgae activity
	 
	
	private GeoPoint[] getRandomGeoPoints()
	{
		GeoPoint[] gps = new GeoPoint[20];

		for (int i = 0; i < gps.length; i++) 
		{
			String coordinates[] = { String.valueOf(Math.random() * 50), String.valueOf(Math.random() * 50) };
			gps[i] = getGeoPointFromCoordinate(coordinates);
		}

		return gps; 
	}
	 

	protected Dialog createOkDialog(String msg) {
		AlertDialog.Builder builder;
		//		switch(id) {
		//		case 0:
		//			// do the work to define the pause Dialog
		//			break;
		//		case 1:
		//			// do the work to define the game over Dialog
		//			break;
		//		default:
		builder = new AlertDialog.Builder(this._mapView.getContext());
		builder.setMessage(msg)
		.setCancelable(false) //(so the user cannot close the dialog with the back button) 
		.setNeutralButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				dialog.cancel();
			}
		});
		AlertDialog alert = builder.create();
		return alert;
		//	}

	}


	
}
*/